# coding:utf-8

import setting as const
from main import *

env.roledefs = {
    'jumpserver': [const.JUMP_IP],
}
config = None


@roles('jumpserver')
def dotask():
    # 上传python文
    const.init_conf('api')
    init_evn()

    execute(up_python_to_jump, '/Users/wlsnow/Projects/deploy-java')

    # 项目打包
    execute(package)
    # 删除项目jar
    execute(package_jar_not_depend)
    # 项目打成tar.gz包
    execute(project_to_targz)
    # 包上传服务器
    jump_package_name = execute(up_package_to_jump)

    execute(jump_file_to_server, jump_package_name.get(const.JUMP_IP))

    execute(jump_back_file)

    # execute(remote_run_command, '/usr/local/tomcat', 'ls')
    # execute(remote_run_command, '/tmp', 'ls')


@roles('jumpserver')
def test_dotask():
    # # 上传python文
    config = const.init_conf('apitest')
    init_evn()
    # 项目打包
    execute(package, 'dev')
    # 删除项目jar
    execute(package_jar_not_depend)
    # 项目打成tar.gz包
    execute(project_to_targz)
    # 备份服务器文件 ROOT目录
    execute(server_back_file)
    # 包上传服务器
    server_package_name = execute(up_package_to_jump)
    # 部署文件
    execute(server_deploy_file, server_package_name.get(config.JUMP_IP))
    # 重启tomcat
    execute(server_restart)

    # execute(server_run_command, '/usr/local/tomcat/webapps', '\ls | grep *.tar.gz')


@roles('jumpserver')
def bank_dotask():
    # # 上传python文
    config = const.init_conf('banktest')
    init_evn()
    # 项目打包
    execute(package, 'dev')
    # 包上传服务器
    execute(server_back_file)

